<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\Collection;

/**
 * @property int $id 
 * @property int $user_id 用户ID
 * @property int $article_id 文章ID
 * @property ?int $parent_id 父评论ID
 * @property string $content 评论内容
 * @property int $like_count 点赞数
 * @property string $status 审核状态
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at
 *
 * @property-read Collection<Comment> $subComments
 * @property-read Article $article
 * @property-read User $user
 */
class Comment extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'comments';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'user_id', 'article_id', 'parent_id', 'content', 'like_count', 'status', 'created_at', 'updated_at'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'user_id' => 'integer', 'article_id' => 'integer', 'parent_id' => 'integer', 'like_count' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function subComments()
    {
        return $this->hasMany(self::class, 'parent_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function article()
    {
        return $this->belongsTo(Article::class);
    }
}